###R filename to compute the rejection frequencies
### filename is the output file of one the the programs Table5a.R, Table 5b.R or Table 5c.R
### It produces a table in tex format

variable <- commandArgs(trailingOnly=TRUE)
filename <- variable[1]

output <- read.table(filename, header = FALSE,sep = "")
nblig<-nrow(output)
nbcol<-ncol(output)



nomstat<-c("$e_t$","$\\tilde{e}_t$","$e_t^*$","$e_t^c$","$e_te_{t-1}$","$e_te_t{t-2}$","$e_te_{t-3}$","$\\tilde{e}_t\\tilde{e}_{t-1}$","$\\tilde{e}_t\\tilde{e}_{t-2}$","$\\tilde{e}_t\\tilde{e}_{t-3}$","$e_t^*e_{t-1}^*$","$e_t^*e_t{t-2}^*$","$e_t^*e_{t-3}^*$","$e_t^ce_{t-1}^c$","$e_t^ce_t{t-2}^c$","$e_t^ce_{t-3}^c$")
lissize=c(100,250,500)
outputtable<-matrix(rep(NA,length(lissize)*16),ncol=length(lissize))
colnames(outputtable) <-as.character(lissize)
rownames(outputtable)<-nomstat
for (i in 1:length(lissize)){
    ns=lissize[i]
    matresul=output[,(6+17*(i-1)):(21+17*(i-1))]
    for(ss in 1:16){
      outputtable[ss,i]=mean(matresul[,ss]>3.84,na.rm=TRUE)*100
    }
}

library(xtable)
outputfile=paste(filename,".tex",sep="")
#print(xtable(outputtable),digits=2,file=outputfile)
toto=noquote(formatC(outputtable,digits=2,format="f"))
write.csv(toto, file = outputfile)

